package dao;

import java.util.List;

import javax.annotation.Resource;

import model.Person;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

@Component
public class PersonDAO {
	
	private HibernateTemplate hibernateTemplate;
	
	@Resource
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	public void add(Person person) {
		hibernateTemplate.save(person);
	}

	public void delete(Person person) {
		hibernateTemplate.delete(person);
	}

	public List<Person> listAll() {
		List<Person> list =hibernateTemplate.find("from Person");
		return list;
	}

	public void update(Person person) {
		hibernateTemplate.update(person);
	}
}
